<template>
	<view class="content">
		<view v-if="todoList.length">
			<view class="list-block">
        <view class="item-block" v-for="(item,index) in todoList" :key='index' @click="toDetail(item.type,item.id)">
          <view class="item-title">{{index + 1}}、{{item.name ? item.name : '-'}}({{item.type | type}})</view>
          <view class="info-block">
            <view class="item-info">申请人：{{item.applicant ? item.applicant : '-'}}</view>
            <view class="item-info">创建时间：{{item.createTime ? item.createTime : '-'}}</view>
          </view>
        </view>
			</view>
		</view>
		<!-- 无数据时显示的内容 -->
		<view v-else class="empty">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import {
		getToDoList
	} from '@/api/workTicket/index.js'
	export default {
		data() {
			return {
				todoList: []
			}
		},
		filters: {
			type(flag) {
				let name = ''
				switch (flag) {
					case 1:
						name = '动火'
						break;
					case 2:
						name = '受限空间'
						break;
					case 3:
						name = '盲板抽堵'
						break;
					case 4:
						name = '高处'
						break;
					case 5:
						name = '吊装'
						break;
					case 6:
						name = '临时用电'
						break;
					case 7:
						name = '动土'
						break;
					case 8:
						name = '断路'
						break;
				}
				return name;
			}
		},
		mounted() {
			this.getList()
		},
		methods: {
			getList() {
				getToDoList().then(res => {
					this.todoList = res
				})
			},
			toDetail(type, id) {
				switch (type) {
					case 1:
						uni.navigateTo({
							url: `/work/addHotWork?operation=4&id=${id}`,
						});
						break;
					case 2:
						uni.navigateTo({
							url: `/work/limitedSpace/index?operation=4&id=${id}`,
						});
						break;
					case 3:
						uni.navigateTo({
							url: `/work/blindPlate/index?operation=4&id=${id}`,
						});
						break;
					case 4:
						uni.navigateTo({
							url: `/work/high/index?operation=4&id=${id}`,
						});
						break;
					case 5:
						uni.navigateTo({
							url: `/work/lifting/index?operation=4&id=${id}`,
						});
						break;
					case 6:
						uni.navigateTo({
							url: `/work/temporaryElectricity/index?operation=4&id=${id}`,
						});
						break;
					case 7:
						uni.navigateTo({
							url: `/work/digging/index?operation=4&id=${id}`,
						});
						break;
					case 8:
						uni.navigateTo({
							url: `/work/circuit/index?operation=4&id=${id}`,
						});
						break;
				}

			}
		}
	}
</script>

<style>
  page {
    background-color: #F4F4F4;
  }
</style>

<style scoped lang="scss">
	.content {
		width: 100%;
		min-height: 100vh;
		background-color: #E6E6E6;
		padding-top: 10px
	}
  
  .list-block {
    padding: 25rpx;
    .item-block {
      background-color: #FFFFFF;
      border-radius: 10rpx;
      box-shadow: 0 0 10 0 #EEEEEE;
      padding: 25rpx;
      margin-bottom: 25rpx;
      .item-title {
        font-size: 30rpx;
        line-height: 42rpx;
        color: #333333;
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-bottom: 30rpx;
      }
      .item-info {
        font-size: 24rpx;
        line-height: 32rpx;
        color: #999999;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .info-block {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
    }
    .item-block:last-child {
      margin-bottom: 0;
    }
  }

	.container {
		display: flex;
		flex-direction: row;
		background-color: white;
		width: 96%;
		height: 78px;
		margin: 0 auto 10px;
		align-items: center;
		border-radius: 20px;
	}

	.imgContainer {
		width: 30%;
		display: flex;
		justify-content: center;

		image {
			width: 80rpx;
			height: 80rpx;
		}
	}

	.todo {
		width: 70%;
	}
</style>
